<?php 

if(Yii::app()->user->hasFlash('model')) {
	Yii::app()->user->flash('model', array('<div class="confirmation">', '</div>'));
	return;
}

Yii::app()->clientScript->registerScriptFile(Html::jsUrl('tiny_mce/jquery.tinymce.js')); 

$tinymce = Html::jsUrl('tiny_mce/tiny_mce.js');
$script = <<<EOD
$('.bigText').tinymce({
script_url : '$tinymce',
theme : "simple",

});
EOD;

if($_SERVER['HTTP_X_REQUESTED_WITH'] ? $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest' : false){
		echo "<script type=\"text/javascript\">$.getScript(\"".Html::jsUrl('tiny_mce/jquery.tinymce.js')."\", function(){".$script."});</script>\n";

	}else{

		Yii::app()->clientScript->registerScriptFile(Html::jsUrl('tiny_mce/jquery.tinymce.js')); 
		Yii::app()->clientScript->registerScript('jq1',$script,CClientScript::POS_READY);
	}

?>

<div class="yiiForm">

<?php
if(Yii::app()->user->hasFlash('model')) {
	Yii::app()->user->flash('model', array('<div class="confirmation">', '</div>'));
	echo "</div>";
	return;
}

$JFV=Yii::app()->jformvalidate;

echo $JFV->beginForm(); 
$JFV->setOptions(array(
	'errorElement'=> 'span',
	'errorClass' => 'invalid',
));
?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo Html::errorSummary($model); ?>

	<div class="simple">
		<?php echo Html::activeLabel($model,'title'); ?>
		<?php echo $JFV->activeTextField($model,'title'); ?>
	</div>
	<div class="simple">
	
		<?php echo Html::activeLabel($model,'content'); ?>
		<?php echo $JFV->activeTextArea($model,'content',array('class'=>'bigText')); ?>
	</div>

	<div class="action">
		<?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Save',array('class'=>'submit')); ?>
	</div>

<?php echo $JFV->endForm(); ?>

</div><!-- form -->

<script type="text/javascript">
$('form').bind("submit", function() { return false; });

$('.submit').bind("click", function () {
  jQuery.ajax({
'type':'POST',
'dataType' : 'html',
'url': jQuery(this).parents("form").attr("action"),
'cache':false,
'data':jQuery(this).parents("form").serialize(),
'success':function(html){
jQuery("#content").html(html)}
});
  return false;
});
</script>
